package com.it.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.it.bean.User;
import com.mysql.jdbc.Connection;


public class UserDao {
	private Connection conn = null;

	public User login(String name, String pwd) {
		conn = Dbutils.getConnection();
		String sql = "select * from t_user where userName=? and passWord=?";
		ResultSet rst = null;
		PreparedStatement prst = null;
		User user = null;
		try {
			prst = conn.prepareStatement(sql);
			prst.setString(1, name);
			prst.setString(2, pwd);
			rst = prst.executeQuery();
			while (rst.next()) {
				user = new User();
				user.setId(rst.getInt("id"));
				user.setUserName(rst.getString("userName"));
				user.setPassWord(rst.getString("passWord"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}
}
